package org.yds.quality.function;


import com.googlecode.aviator.runtime.function.AbstractVariadicFunction;
import com.googlecode.aviator.runtime.type.AviatorDouble;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.util.Map;

public class SumFunction extends AbstractVariadicFunction {


    @Override
    public AviatorObject variadicCall(Map<String, Object> env, AviatorObject... args) {
        Double sum = 0D;
        // 遍历所有参数
        for (AviatorObject arg : args) {
            // 获取参数值并转换为 boolean 类型
            Number value = (Number) arg.getValue(env);
            sum += value.doubleValue();
        }
        return new AviatorDouble(sum);
    }

    @Override
    public String getName() {
        return "SUM"; // 函数名称
    }


}
